package servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import modelo.Persona;
import negocio.CronogramaNegocio;
import negocio.LocalNegocio;
import excepcion.DAOExcepcion;

/**
 * Servlet implementation class InsertarCronogramaServlet
 */
@WebServlet("/InsertarCronogramaServlet")
public class InsertarCronogramaServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public InsertarCronogramaServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
 		
		String diaInicio = request.getParameter("txtDiaInicio");
		String diaFin = request.getParameter("txtDiaFin");
		String horaInicio = request.getParameter("cboHoraInicio");
		String horaFin = request.getParameter("cboHoraFin");
		Double tarifa =Double.parseDouble(request.getParameter("txtTarifa"));
		
		int ohoraInicio = Integer.parseInt(request.getParameter("cboHoraInicio"));
		int ohoraFin= Integer.parseInt(request.getParameter("cboHoraFin"));
		String newHora ="";
		System.out.println("hasta aqui llegue"); 
		CronogramaNegocio negocio = new CronogramaNegocio();
		try {
			for (int i= ohoraInicio ; i <= ohoraFin; i++){
				if (i<10){
					newHora = "0" + i + ":00:00";
					negocio.insertarCronograma(diaInicio, newHora, tarifa, "");
				}else
					newHora =  i + ":00:00";
				negocio.insertarCronograma(diaInicio, newHora, tarifa, "");
			}
			//System.out.println("el valor de i es: " + i); 
			System.out.println("Se ingreso  el Cronogram");
			response.sendRedirect("menu.jsp");
		} catch (DAOExcepcion e) {
			RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
			rd.forward(request, response);
		}		
		
	}

}
